package com.smart.tool.pipeline;

/**
 * @Author xiaoqiang
 * @Version Profit.java, v 0.1 2024年10月25日 下午3:44 xiaoqiang
 * @Description: TODO
 */
public class Profit {

    public static void main(String[] args) {
        int [] prices = {7,6,4,3,1};
        System.out.println(maxProfit(prices));
    }
    public static int maxProfit(int[] prices){
        if(prices==null||prices.length==0){
            return 0;
        }
        int profit = 0;
        int minPrice = prices[0];
        for(int i =0;i<prices.length;i++){
            if(prices[i]<minPrice){
                minPrice = prices[i];
            }else{
                profit = Math.max(profit,prices[i]-minPrice);
            }
        }
        return profit;
    }
}
